<!--
 * @author guojiteng
 新建/编辑关口
 -->
<template>
  <div class="a-pass-manage">
    <div class="a-pass-manage-title">
      <span v-if="pt === 'g'">一键生成</span>
      <span v-else> 新建/编辑关口</span>
    </div>
    <section v-loading="loading" class="a-pass-manage-main">
      <el-form ref="form" :model="form" :rules="rules" label-width="150px" class="form">
        <el-form-item v-if="!pt" label="关口名称" prop="name">
          <el-input v-model="form.name" placeholder="请输入关口名称" />
        </el-form-item>
        <el-form-item v-if="pt === 'g'" label="导入题库" required>
          <!--          <el-button v-if="!fileName" size="mini" @click="dialogUploadVisible=true" type="primary">上传模板</el-button>-->
          <!--          <el-tag-->
          <!--              v-else-->
          <!--              closable-->
          <!--              @close="handleFileClose()"-->
          <!--              type="primary">-->
          <!--            {{fileName}}-->
          <!--          </el-tag>-->
          <div class="file-box">
            <el-upload
              ref="upload"
              :auto-upload="false"
              :on-success="uploadSuccess"
              :on-error="uploadError"
              :action="uploadaction"
              :headers="uploadHeaders"
              :data="uploadData"
              accept=".xls, .xlsx"
              class="upload-demo"
              drag
            >
              <i class="el-icon-upload" />
              <div class="el-upload__text">
                将文件拖到此处，或
                <em>点击上传</em>
              </div>
              <div slot="tip" class="el-upload__tip" style="text-align: right">
                只能上传.xls,.xlsx
                <el-button type="text" @click="handleDownload">下载模板</el-button>
              </div>
            </el-upload>
          </div>
        </el-form-item>

        <el-form-item :label="pt === 'g' ? '关联题库分类' : '关联题库'" prop="extend1">
          <el-button size="mini" type="primary" @click="dialogPowerVisible = true">
            {{ pt === 'g' ? '选择题库分类' : '选择题库' }}
          </el-button>
          <el-tag
            v-if="form.extend2"
            :closable="state === 'create' || state === 'update'"
            type="primary"
            style="height: auto;white-space: normal;"
            @close="handleClose()"
          >
            {{ form.extend2 }}
          </el-tag>
        </el-form-item>
        <el-form-item v-if="!pt" label="题目难度类型" prop="difficultyCategory">
          <el-radio-group v-model="form.difficultyCategory" @input="getType()">
            <el-radio :label="0">全部随机</el-radio>
            <el-radio :label="1">难度随机</el-radio>
            <el-radio :label="2">题型随机</el-radio>
          </el-radio-group>
        </el-form-item>
        <template v-if="form.difficultyCategory === 0">
          <el-form-item :label="pt === 'g' ? '每关出题数量' : '出题数量'" prop="quesNums">
            <el-input
              v-if="pt === 'g'"
              v-model.number="form.quesNums"
              oninput="value=value.replace(/[^0-9]/g,'')"
              placeholder="每关出题数量"
            />
            <el-input
              v-else
              v-model.number="form.quesNums"
              oninput="value=value.replace(/[^0-9]/g,'')"
              placeholder="出题数量"
            />
          </el-form-item>

          <template v-if="pt === 'g'">
            <el-form-item v-if="pt === 'g'" label="关口数量" class="gatewayNum">
              <el-input v-model.number="form.num" oninput="value=value.replace(/[^0-9]/g,'')" placeholder="请输入关口数量" />
            </el-form-item>
            <p class="tip" style="color: red; font-size: 12px; margin-left: 150px">
              *如您不输入关口数量，系统会根据每关出题数量及题库数量自动生成关口。
            </p>
          </template>

          <el-form-item label="每题分值" prop="perQuesFraction">
            <el-input-number v-model="form.perQuesFraction" :precision="2" />
          </el-form-item>
        </template>
        <template v-else>
          <p class="tip" style="color: red; font-size: 12px; margin-left: 150px">* 请至少填写一组出题数量和分值,其他出题数量填写0。</p>
          <el-form-item :label="form.difficultyCategory === 1 ? '初级题数量' : '单选题数量'" prop="primaryQuesNum">
            <el-input
              v-model.number="form.primaryQuesNum"
              oninput="value=value.replace(/[^0-9]/g,'')"
              placeholder="请输入出题数量"
            />
          </el-form-item>
          <el-form-item label="每题分值" prop="primaryQuesFraction">
            <el-input-number v-model="form.primaryQuesFraction" :precision="2" />
          </el-form-item>

          <el-form-item :label="form.difficultyCategory === 1 ? '中级题数量' : '多选题数量'" prop="intermediateQuesNum">
            <el-input
              v-model.number="form.intermediateQuesNum"
              oninput="value=value.replace(/[^0-9]/g,'')"
              placeholder="请输入出题数量"
            />
          </el-form-item>
          <el-form-item label="每题分值" prop="intermediateQuesFraction">
            <el-input-number v-model="form.intermediateQuesFraction" :precision="2" />
          </el-form-item>
          <el-form-item :label="form.difficultyCategory === 1 ? '高级题数量' : '判断题数量'" prop="advancedQuesNum">
            <el-input
              v-model.number="form.advancedQuesNum"
              oninput="value=value.replace(/[^0-9]/g,'')"
              placeholder="请输入出题数量"
            />
          </el-form-item>
          <el-form-item label="每题分值" prop="advancedQuesFraction">
            <el-input-number v-model="form.advancedQuesFraction" :precision="2" />
          </el-form-item>
          <el-form-item :label="form.difficultyCategory === 1 ? '技师题数量' : '填空题数量'" prop="technicianQuesNum">
            <el-input
              v-model.number="form.technicianQuesNum"
              oninput="value=value.replace(/[^0-9]/g,'')"
              placeholder="请输入出题数量"
            />
          </el-form-item>
          <el-form-item label="每题分值" prop="technicianQuesFraction">
            <el-input-number v-model="form.technicianQuesFraction" :precision="2" />
          </el-form-item>
        </template>

        <el-form-item label="过关条件" prop="clearanceConditions">
          <el-radio-group v-model="form.clearanceConditions">
            <el-radio :label="1">分数</el-radio>
            <el-radio :label="2">正确率</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="过关具体值" prop="clearanceConditionsValue">
          <el-input
            v-model.number="form.clearanceConditionsValue"
            oninput="value=value.replace(/[^0-9]/g,'')"
            placeholder="请输入过关具体值"
          />
        </el-form-item>
        <el-form-item label="重复闯关类别" prop="repeatPass">
          <el-radio-group v-model="form.repeatPass">
            <el-radio :label="0">不限次数</el-radio>
            <el-radio :label="1">自定义每日重复闯关次数</el-radio>
            <el-radio :label="2">不可重复闯关</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item v-if="form.repeatPass === 1" label="闯关次数" prop="repeatedNum">
          <el-input
            v-model.number="form.repeatedNum"
            oninput="value=value.replace(/[^0-9]/g,'')"
            placeholder="请输入闯关次数"
          />
        </el-form-item>
        <el-form-item label="关口时限（秒）" prop="limitTime">
          <el-input v-model.number="form.limitTime" placeholder="请输入关口时限(秒)" />
        </el-form-item>
      </el-form>
    </section>

    <section class="a-pass-manage-footer">
      <el-button style="padding: 10px 30px;" @click="onCancel">取 消</el-button>
      <el-button type="primary" @click="onSubmint('form')">确 定</el-button>
    </section>
    <!--选择题库  -->
    <el-dialog
      v-el-drag-dialog
      custom-class="my-dialog"
      title="选择题库分类"
      :visible.sync="dialogPowerVisible"
      center
      width="450px"
      :close-on-click-modal="false"
    >
      <choose-qs
        v-if="dialogPowerVisible"
        ref="PowerTreeFun"
        :is-selsct="true"
        @subQs="getQsFun"
        @dialogPower="dialogPower"
      />
      <div slot="footer" class="dialog-footer">
        <el-button style="padding: 8px 30px;" @click="dialogPowerVisible = false">取消</el-button>
        <el-button style="padding: 8px 30px;" type="primary" @click="powerTreeFun">确定</el-button>
      </div>
    </el-dialog>
    <!--选择模板-->
    <el-dialog
      v-show="dialogUploadVisible"
      v-el-drag-dialog
      :close-on-click-modal="false"
      :visible.sync="dialogUploadVisible"
      title="导入关口"
      center
      width="500px"
      @close="handleClosed"
    >
      <el-upload
        ref="upload"
        :auto-upload="false"
        :on-success="uploadSuccess"
        :on-error="uploadError"
        :action="uploadaction"
        :headers="uploadHeaders"
        :data="uploadData"
        accept=".xls, .xlsx"
        class="upload-demo"
        drag
      >
        <i class="el-icon-upload" />
        <div class="el-upload__text">
          将文件拖到此处，或
          <em>点击上传</em>
        </div>
        <div slot="tip" class="el-upload__tip" style="text-align: right">
          只能上传.xls,.xlsx
          <el-button type="text" @click="handleDownload">下载模板</el-button>
        </div>
      </el-upload>
      <span slot="footer" class="dialog-footer">
        <el-button style="padding: 8px 30px;" type="primary" @click="handleClosed">取消</el-button>
        <el-button style="padding: 8px 30px;" type="primary" @click="submitUpload()">确认</el-button>
      </span>
    </el-dialog>
    <!-- 导入的错误信息  -->
    <el-dialog
      v-el-drag-dialog
      :close-on-click-modal="false"
      :visible.sync="dialogUploadErrorTextVisible"
      title="错误信息"
      center
      width="500px"
    >
      <div class="error-text" style="height: 600px;overflow-y: auto">
        <el-row>
          <el-col v-for="(item, index) in uploadErrorList" :key="index" :span="24" style="margin-bottom: 10px;">
            {{ index + 1 }}、{{ item }}
          </el-col>
        </el-row>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button
          style="padding: 8px 30px;"
          type="primary"
          @click="dialogUploadErrorTextVisible = false"
        >关闭</el-button>
        <el-button style="padding: 8px 30px;" type="primary" @click="copyErrorText()">复制</el-button>
      </span>
    </el-dialog>
    <!-- 导入的错误信息  -->
    <!--关口列表预览-->
    <el-dialog
      v-el-drag-dialog
      :close-on-click-modal="false"
      :visible.sync="dialogTableVisible"
      title="关口预览"
      center
      width="1300px"
    >
      <div class="pass-box">
        <p>
          总题数：<span style="color:red;">{{ passObj.totalQuesNum || '0' }}</span>&nbsp;&nbsp;&nbsp;&nbsp; 需要题数：<span
            style="color:red;"
          >{{ passObj.needQuesNum || '0' }}</span>&nbsp;&nbsp;&nbsp;&nbsp; 关口数：<span
            style="color:red;"
          >{{ passObj.num || '0' }}</span>&nbsp;&nbsp;&nbsp;&nbsp;
        </p>
        <el-table height="560" :data="passData" border style="width: 100%">
          <el-table-column align="center" width="80" prop="num" label="关口序号" />

          <el-table-column label="出题数量">
            <template slot-scope="scope">
              <el-input v-model="scope.row.quesNums" oninput="value=value.replace(/[^0-9]/g,'')" placeholder="请输入" />
            </template>
          </el-table-column>
          <el-table-column label="每题分值">
            <template slot-scope="scope">
              <el-input
                v-model="scope.row.perQuesFraction"
                oninput="value=value.replace(/[^0-9]/g,'')"
                placeholder="请输入"
              />
            </template>
          </el-table-column>
          <el-table-column label="答题时间（秒）">
            <template slot-scope="scope">
              <el-input v-model="scope.row.limitTime" oninput="value=value.replace(/[^0-9]/g,'')" placeholder="请输入" />
            </template>
          </el-table-column>
          <el-table-column label="过关条件">
            <template slot-scope="scope">
              <el-radio-group v-model="scope.row.clearanceConditions">
                <el-radio :label="1">分数</el-radio>
                <el-radio style="margin-top: 20px;" :label="2">正确率</el-radio>
              </el-radio-group>
            </template>
          </el-table-column>
          <el-table-column label="过关具体值">
            <template slot-scope="scope">
              <el-input
                v-model="scope.row.clearanceConditionsValue"
                oninput="value=value.replace(/[^0-9]/g,'')"
                placeholder="请输入"
              />
            </template>
          </el-table-column>
          <el-table-column label="重复闯关类别">
            <template slot-scope="scope">
              <el-radio-group v-model="scope.row.repeatPass">
                <el-radio :label="0">不限次数</el-radio>
                <el-radio style="margin-top: 20px;" :label="1">自定义每日重复闯关次数</el-radio>
                <el-radio style="margin-top: 20px;" :label="2">不可重复闯关</el-radio>
              </el-radio-group>
            </template>
          </el-table-column>
          <el-table-column label="重复答题次数">
            <template slot-scope="scope">
              <el-input
                v-if="scope.row.repeatPass === 1"
                v-model="scope.row.repeatedNum"
                oninput="value=value.replace(/[^0-9]/g,'')"
                placeholder="请输入"
              />
            </template>
          </el-table-column>
        </el-table>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button style="padding: 8px 30px;" type="primary" @click="dialogTableVisible = false">关闭</el-button>
        <el-button style="padding: 8px 30px;" type="primary" @click="generateFun()">生成</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
import {specialText} from '@/utils/validate'
import {mapGetters} from 'vuex'
import ImageUpload from '@/components/ImageUpload'
import ChooseQs from '@/views/skill/answerRush/components/chooseQs'
import elDragDialog from '@/directive/el-drag-dialog'
import {insert, update, get, generate} from './../api/pass'
import {exportSign, importSign} from '@/utils/fileImportOrExportSign'
import TemplateList from '@/views/templatelib/pages/list'

export default {
  name: 'PassManage',
  components: {TemplateList, ImageUpload, ChooseQs},
  directives: {elDragDialog},
  data() {
    return {
      dialogTableVisible: false,
      dialogPowerVisible: false,
      dom: '',
      qsName: [],
      qsId: [],
      options: [], // 闯关策略模板
      loading: false,
      form: {
        id: '',
        dataId: '',
        name: '',
        num: '',
        difficultyCategory: 0,
        quesNums: '',
        perQuesFraction: '',
        clearanceConditions: 1,
        clearanceConditionsValue: '',
        repeatPass: 0,
        repeatedNum: '',
        extend1: '',
        extend2: '',
        limitTime: '',
        primaryQuesNum: '', // 初级题数量  /   单选题数量
        primaryQuesFraction: '', // 初级题分值  /   单选题分值
        intermediateQuesNum: '', // 中级题数量  /   多选题数量
        intermediateQuesFraction: '', // 中级题分值  /   多选题分值
        advancedQuesNum: '', // 高级题数量  /   判断题数量
        advancedQuesFraction: '', // 高级题分值  /   判断题分值
        technicianQuesNum: '', // 技师题数量  /   填空题数量
        technicianQuesFraction: '' // 技师题分值  /   填空题分值
      },
      rules: {
        name: [
          {required: true, message: '请输入关口名称', trigger: 'blur'},
          {validator: specialText, trigger: 'blur'},
          {min: 1, max: 50, message: '长度在 1 到 50 个字符', trigger: 'blur'}
        ],
        difficultyCategory: [{required: true, message: '请选择题目难度类型', trigger: 'change'}],
        num: [{required: true, message: '请输入关口数量', trigger: 'blur'}],
        quesNums: [{required: true, message: '请输入出题数量', trigger: 'blur'}],
        perQuesFraction: [{required: true, message: '请输入每题分值', trigger: 'blur'}],

        clearanceConditions: [{required: true, message: '请选择过关条件', trigger: 'change'}],
        clearanceConditionsValue: [{required: true, message: '请输入过关具体值', trigger: 'blur'}],
        repeatPass: [{required: true, message: '请选择重复闯关类别', trigger: 'change'}],
        repeatedNum: [{required: true, message: '请输入闯关次数', trigger: 'blur'}],
        extend1: [{required: true, message: '请选择题库分类', trigger: 'change'}],
        limitTime: [{required: true, message: '请输入关口时限', trigger: 'blur'}]
      },
      state: 'create',
      t: '0',
      type: 1,
      pt: '', // 页面类型，如果值为g时，代表为一键生成
      fileName: '',
      dialogUploadVisible: false,
      uploadData: {
        dataId: ''
      },
      uploadaction: '/API-ENTERPRISE-BACKEND/backend/rushPass/previewBuild',
      uploadHeaders: {ttsxbwqm: '', ttsxsjzc: '', ttsxyhcs: ''},
      dialogUploadErrorTextVisible: false,
      uploadErrorList: [],
      uploadLoding: '',
      passObj: '',
      passData: [] // 预览关口数据
    }
  },
  computed: {
    ...mapGetters(['user'])
  },
  watch: {
    'form.classifyId': {
      handler(newName, oldName) {
        if (this.$refs.classify) {
          this.$refs.classify.dropDownVisible = false
        }
      },
      immediate: true,
      deep: true
    }
  },
  created() {
    this.state = this.$route.query.type === 'c' ? 'create' : 'update'
    this.pt = this.$route.query.pt || ''
    if (this.$route.query.type === 'u') {
      if (this.$route.query.ui) {
        this.getData(this.$route.query.ui)
      } else {
        this.$message({
          showClose: true,
          message: '参数异常！',
          type: 'warning',
          onClose: () => {
            this.$router.back()
          }
        })
      }
    } else {
      if (this.$route.query.i) {
        this.form.dataId = this.$route.query.i
      }
    }
  },

  methods: {
    getType() {
      this.form.primaryQuesNum = ''
      this.form.primaryQuesFraction = 0
      this.form.intermediateQuesNum = ''
      this.form.intermediateQuesFraction = 0
      this.form.advancedQuesNum = ''
      this.form.advancedQuesFraction = 0
      this.form.technicianQuesNum = ''
      this.form.technicianQuesFraction = 0
      this.form.intermediateQuesNum = ''
      this.form.quesNums = ''
      this.form.perQuesFraction = 0
    },
    /**
     * 生成关口
     */
    generateFun() {
      const loading = this.$loading({
        lock: true,
        text: '请稍后',
        spinner: 'el-icon-loading',
        background: 'rgba(0, 0, 0, 0.3)'
      })
      return new Promise((resolve, reject) => {
        generate({uuid: this.passObj.uuid, rushPassList: JSON.stringify(this.passData)})
          .then((res) => {
            loading.close()
            if (res.data.code === '200') {
              this.$message.success('关口生成成功')
              this.onCancel()
            }
          })
          .catch((error) => {
            loading.close()
            reject(error)
          })
      })
    },
    /**
     * 复制错误消息
     */
    copyErrorText() {
      let val = ''
      this.uploadErrorList.forEach((item) => {
        val += item + '\n'
      })
      const input = document.createElement('input')
      input.setAttribute('readonly', 'readonly')
      input.setAttribute('value', val)
      document.body.appendChild(input)
      input.select()
      if (document.execCommand('copy')) {
        document.execCommand('copy')
        this.$message({
          title: '成功',
          message: '复制成功！',
          type: 'success',
          duration: 1500
        })
      }
      document.body.removeChild(input)
    },
    /**
     * 预览模板
     * */
    handleUpload() {
      this.uploadHeaders = importSign({}, this.form)
      this.uploadData = this.form
      this.uploadLoding = this.$loading({
        lock: true,
        text: '请稍后',
        spinner: 'el-icon-loading',
        background: 'rgba(0, 0, 0, 0.3)'
      })
      setTimeout(() => {
        this.$nextTick(() => {
          this.$refs.upload.submit()
        })
      }, 1000)
    },
    submitUpload() {
      if (this.$refs['upload'].uploadFiles.length === 0) {
        this.$message.error('请上传文件')
      } else {
        this.fileName = this.$refs['upload'].uploadFiles[0].name
        this.dialogUploadVisible = false
      }
    },
    /**
     * 更换模板
     * */
    handleFileClose() {
      this.fileName = ''
      this.$refs.upload.clearFiles()
    },
    handleDownload() {
      const link = document.createElement('a')
      link.style.display = 'none'
      // link.href = '/API-ENTERPRISE-BACKEND/backend/rushPass/downloadPassTemplate' + exportSign({ type: '1' }).paramStr
      link.href = '/API-ENTERPRISE-BACKEND/backend/questionBank/downloadQuestionTemplate' + exportSign({}).paramStr
      link.setAttribute('download', '关口模版.xlsx')
      link.setAttribute('target', '_blank')
      document.body.appendChild(link)
      link.click()
      document.body.removeChild(link)
    },

    uploadSuccess(data) {
      this.uploadLoding.close()
      if (data.code === '200') {
        this.$message({
          message: '成功',
          type: 'success'
        })
        this.dialogUploadVisible = false
        this.$refs.upload.clearFiles()
        this.passObj = data.data || ''
        this.passData = data.data.list || []
        this.dialogTableVisible = true
      } else {
        this.$message.error(data.msg || '网络异常')
        if (data.data.fileid) {
          const link = document.createElement('a')
          link.style.display = 'none'
          link.href = '/API-ENTERPRISE-BACKEND/backend/rushPass/downloadCheckFile' + exportSign({errorId: data.data.fileid}).paramStr
          link.setAttribute('download', '关口错误模版.xlsx')
          link.setAttribute('target', '_blank')
          document.body.appendChild(link)
          link.click()
          document.body.removeChild(link)
        }
        this.$refs.upload.clearFiles()
        if (data.data) {
          this.uploadErrorList = data.data
          this.dialogUploadErrorTextVisible = true
        }
      }
    },
    uploadError(err) {
      this.uploadLoding.close()
      this.$message.error(err || '网络异常')
    },
    handleClosed() {
      this.dialogUploadVisible = false
      this.$refs.upload.clearFiles()
    },
    /**
     * 去掉某个题库
     * */
    handleClose() {
      this.form.extend1 = ''
      this.form.extend2 = ''
    },
    /**
     * 题库
     */
    getQsFun(obj) {
      this.form.extend2 = obj.menuName
      this.form.extend1 = obj.menuIds
      this.$refs['form'].validateField('extend1', (val) => {
        if (!val) {
          return true
        } else {
          return false
        }
      })
    },
    /**
     * 关闭权限弹框
     */
    dialogPower(val) {
      this.dialogPowerVisible = val
    },
    /**
     * 确认题库
     */
    powerTreeFun() {
      this.$refs.PowerTreeFun.saveData()
      this.dialogPowerVisible = false
    },

    /**
     * 根编辑回显
     */
    getData(id) {
      const loading = this.$loading({
        lock: true,
        text: '请稍后',
        spinner: 'el-icon-loading',
        background: 'rgba(0, 0, 0, 0.3)'
      })
      return new Promise((resolve, reject) => {
        get({id: id})
          .then((res) => {
            loading.close()
            const data = res.data.data
            for (const key in this.form) {
              this.form[key] = data[key]
            }
          })
          .catch((error) => {
            loading.close()
            reject(error)
          })
      })
    },

    /**
     * 取消闯关维护
     */
    onCancel() {
      // this.$router.push({ path: this.$filterPath('index'), query: { t: this.t }})
      this.$router.back()
    },

    updateData() {
      const loading = this.$loading({
        lock: true,
        text: '请稍后',
        spinner: 'el-icon-loading',
        background: 'rgba(0, 0, 0, 0.3)'
      })
      return new Promise((resolve, reject) => {
        update(this.form)
          .then(() => {
            this.dialogVisible = false
            loading.close()
            this.$message({
              title: '成功',
              message: '编辑成功',
              type: 'success',
              duration: 2000
            })
            this.onCancel()
          })
          .catch((error) => {
            reject(error)
            loading.close()
          })
      })
    },
    insertData() {
      const loading = this.$loading({
        lock: true,
        text: '请稍后',
        spinner: 'el-icon-loading',
        background: 'rgba(0, 0, 0, 0.3)'
      })
      return new Promise((resolve, reject) => {
        insert(this.form)
          .then(() => {
            this.dialogVisible = false
            loading.close()
            this.$message({
              title: '成功',
              message: '创建成功',
              type: 'success',
              duration: 2000
            })
            this.onCancel()
          })
          .catch((error) => {
            reject(error)
            loading.close()
          })
      })
    },
    /**
     * 发布闯关
     */
    onSubmint() {
      const ths = this
      if (this.state === 'create') {
        this.$refs['form'].validate((valid) => {
          if (valid) {
            if (this.pt === 'g') {
              if (this.$refs['upload'].uploadFiles.length === 0) {
                this.$message.error('请上传文件')
                return
              } else {
                this.fileName = this.$refs['upload'].uploadFiles[0].name
                this.dialogUploadVisible = false
              }
              this.handleUpload()
              return
            }
            if (this.form.difficultyCategory !== 0) {
              if (
                (this.form.primaryQuesNum === '' && this.form.primaryQuesFraction === 0) ||
                  (this.form.intermediateQuesNum === '' && this.form.intermediateQuesFraction === 0) ||
                  (this.form.advancedQuesNum === '' && this.form.advancedQuesFraction === 0) ||
                  (this.form.technicianQuesNum === '' && this.form.technicianQuesFraction === 0)
              ) {
                this.$message({
                  message: '请至少填写一组出题数量和分值',
                  type: 'warning'
                })
                return
              }

              if (
                this.form.primaryQuesFraction === 0 &&
                  this.form.intermediateQuesFraction === 0 &&
                  this.form.advancedQuesFraction === 0 &&
                  this.form.technicianQuesFraction === 0
              ) {
                this.$confirm('所有分值均为0，请确认是否提交?', '提示', {
                  confirmButtonText: '确定',
                  cancelButtonText: '取消',
                  type: 'warning'
                })
                  .then(() => {
                    ths.insertData()
                  })
                  .catch(() => {
                    this.$message({
                      type: 'info',
                      message: '已取消'
                    })
                  })
                return
              }
              this.insertData()
            } else {
              this.insertData()
            }
          } else {
            console.log('error submit!!')
            return false
          }
        })
      } else {
        this.$refs['form'].validate((valid) => {
          if (valid) {
            if (this.form.difficultyCategory !== 0) {
              if (
                (this.form.primaryQuesNum === '' && this.form.primaryQuesFraction === 0) ||
                  (this.form.intermediateQuesNum === '' && this.form.intermediateQuesFraction === 0) ||
                  (this.form.advancedQuesNum === '' && this.form.advancedQuesFraction === 0) ||
                  (this.form.technicianQuesNum === '' && this.form.technicianQuesFraction === 0)
              ) {
                this.$message({
                  message: '请至少填写一组出题数量和分值',
                  type: 'warning'
                })
                return
              }

              if (
                this.form.primaryQuesFraction === 0 &&
                  this.form.intermediateQuesFraction === 0 &&
                  this.form.advancedQuesFraction === 0 &&
                  this.form.technicianQuesFraction === 0
              ) {
                this.$confirm('所有分值均为0，请确认是否提交?', '提示', {
                  confirmButtonText: '确定',
                  cancelButtonText: '取消',
                  type: 'warning'
                })
                  .then(() => {
                    ths.updateData()
                  })
                  .catch(() => {
                    this.$message({
                      type: 'info',
                      message: '已取消'
                    })
                  })
                return
              }
              ths.updateData()
            } else {
              ths.updateData()
            }
          } else {
            return false
          }
        })
      }
    }
  }
}
</script>
<style rel="stylesheet/scss" lang="scss">
.a-pass-manage {
  background-color: #fff;
  min-height: calc(100vh - 60px);
  max-height: calc(100vh - 60px);
  overflow: hidden;

  .el-radio {
    margin-top: 12px;
  }

  .file-box {
    width: 300px;
  }

  .upload-demo {
    .el-upload-dragger {
      width: 100%;
    }

    display: flex;
    flex-direction: column;
    justify-content: center;
  }

  .a-pass-manage-title {
    position: relative;
    height: 40px;
    line-height: 40px;
    padding: 0 20px;
    background-color: #ffffff;
    border-bottom: 1px solid #e5e5e5;
    font-family: PingFangSC-Medium;
    font-weight: bold;
    color: rgba(51, 51, 51, 1);
    font-size: 14px;

    &:before {
      content: '';
      position: absolute;
      width: 2px;
      @include bg-color($mainColor);
      top: 13px;
      bottom: 13px;
      left: 15px;
    }
  }

  .a-pass-manage-main {
    position: absolute;
    top: 50px;
    left: 0;
    right: 0;
    bottom: 52px;
    box-sizing: border-box;
    padding: 0 10px;
    overflow: hidden;

    &::-webkit-scrollbar {
      width: 8px; /*对垂直流动条有效*/
      height: 1px; /*对水平流动条有效*/
    }

    /** 滚动条轨道*/
    &::-webkit-scrollbar-track {
      box-shadow: inset 0 0 6px rgba(0, 0, 0, 0.1);
      background-color: white;
      border-radius: 3px;
    }

    /** 滚动条里面小方块*/
    &::-webkit-scrollbar-thumb {
      height: 32px;
      border-radius: 5px;
      box-shadow: inset 0 0 4px rgba(0, 0, 0, 0.1);
      background-color: #eaeaea;
    }

    &:hover {
      overflow: auto;
    }

    .form {
      width: 1000px !important;
      margin: 0 auto;

      .el-select {
        width: 100%;
      }

      .line {
        text-align: center;
      }

      .gatewayNum {
        margin-bottom: 0px;
      }
    }

    .select-data {
      display: inline-block;
      background: rgba(246, 246, 246, 1);
      border-radius: 4px;
      font-size: 14px;
      font-family: PingFangSC-Regular;
      font-weight: 400;
      color: rgba(51, 51, 51, 1);
      padding: 0 10px;
      margin-right: 5px;
      margin-bottom: 8px;

      i {
        cursor: pointer;
        padding-left: 5px;
      }
    }

    .selectbtn {
      display: inline-block;
      width: 120px;
      background: rgba(255, 255, 255, 1);
      @include border-color(1px, dotted, $mainColor);
      border-radius: 4px;
      font-size: 14px;
      font-family: PingFangSC-Regular;
      font-weight: 400;
      @include font-color($mainColor);
      text-align: center;
      cursor: pointer;
    }
  }

  .a-pass-manage-footer {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    text-align: center;
    padding: 10px 0;
    background-color: white;
    box-shadow: 0 -3px 6px #f5f5f5;
  }
}
</style>
<style lang="scss">
.a-pass-manage {
  .classify-tree-con {
    position: relative;
    height: 400px;
    overflow: hidden;

    .classify-tree-con-scrollbar {
      overflow: hidden;

      .el-scrollbar__wrap {
        max-height: 381px;
      }
    }

    .custom-tree-node {
      display: flex;
      align-items: center;
      justify-content: space-between;
      font-size: 14px;
      width: 100%;

      .tree-node-txt {
        flex: 1;
      }
    }
  }
}
</style>
